<?php
declare (strict_types = 1);

namespace app\controller;

use app\common\model\Ad;
use think\facade\Cache;
use think\facade\Db;
use think\facade\View;
use think\Request;

class Download extends Common
{

    public function __construct()
    {
        parent::__construct();
        
        $ad = Ad::where('board_id',7)->select();
        View::assign("ad",$ad);
    }
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        //轮播广告
        $banner = Db::name("ad")->where("board_id",7)->where("status",1)
            ->select()->toArray();
        $banner = banner($banner);
        View::assign("banner",$banner);
        $cids = [
            10,27
            ,28
            ,29
            ,30
            ,38
            ,39
            ,16,52,12,41,48,25
        ];
        $where[] = ["cate_id","in",$cids];

        if(!isset($where)){
            $where = 1;
        }

        $list = \app\common\model\Content::with("user")
            ->where($where)
            ->order("id DESC")
            ->paginate([
                'query'=> $this->params,
            ]);
        //echo Db::name("article")->getLastSql();die;
        View::assign("list",$list);
        return  view('index/index');
    }

    public function search()
    {
        $keywords = \think\facade\Request::get("keywords");
        if($keywords){
            $keywords = trim($keywords);
            View::assign('keywords',$keywords);
        }
        $list = \app\common\model\Article::with("user")
            ->whereLike('title',"%{$keywords}%")
            ->order("id DESC")
            ->paginate([
                'query'=> $this->params,
            ]);

        //echo Db::name("article")->getLastSql();die;
        View::assign("list",$list);
        return  view('index');
    }



    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        //
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request)
    {
        //
    }

    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read($id)
    {
        //
    }

    /**
     * 显示编辑资源表单页.
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        //
    }

    public function cache_clear()
    {
        Cache::clear();
    }

    public function test()
    {
        return view('public/echart');
    }
}
